package server

import (
	"codeforces/src/task"
	"encoding/json"
	"log"

	"github.com/Shopify/sarama"
)

func handleReq(consumer sarama.PartitionConsumer, outChan chan task.ITask, logger *log.Logger) {

	for msg := range consumer.Messages() {
		logger.Output(1, string(msg.Value))
		a := &task.Arg{}
		if e := json.Unmarshal(msg.Value, a); e == nil {
			task := task.NewTask(*a)
			if task == nil {
				continue
			}
			task.SetKey(string(msg.Key))
			outChan <- task
		} else {
			logger.Output(1, "parse req json fail :"+string(msg.Value))
		}
	}
}
